package com.example.controller;

import com.example.entity.Device;
import com.example.entity.DeviceOperation;
import com.example.service.DeviceOperationService;
import com.example.util.AjaxResult;
import com.example.util.PageResult;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/api")
public class DeviceOperationController {

    @Autowired
    private DeviceOperationService deviceOperationService;

    /**
     * 获取设备操作记录
     * @param deviceId
     * @return
     */
    @GetMapping("/devices/{deviceId}/operations")
    public AjaxResult getDeviceOperations(@PathVariable Integer deviceId) {
        PageResult<DeviceOperation> deviceOperationResult = deviceOperationService.pageDeviceOperation(deviceId);
        if (ObjectUtils.isNotEmpty(deviceOperationResult)){
            return AjaxResult.success("查询成功", deviceOperationResult);
        }else {
            return AjaxResult.error("查询失败");
        }

    }

}
